home *** CD-ROM | disk | FTP | other *** search
/ X User Tools / X User Tools (O'Reilly and Associates)(1994).ISO / sun4c / archive / tcltk.z / tcltk / man / cat3 / ExprLong.3 < prev    next >
Text File  |  1994-09-20  |  5KB  |  133 lines

  1.  
  2.  
  3.  
  4. Tcl_ExprLong(3)      Tcl Library Procedures                   7.0
  5.  
  6.  
  7.  
  8. _________________________________________________________________
  9.  
  10. NAME
  11.      Tcl_ExprLong, Tcl_ExprDouble, Tcl_ExprBool, Tcl_ExprString -
  12.      evaluate an expression
  13.  
  14. SYNOPSIS
  15.      #include <tcl.h>
  16.  
  17.      int
  18.      Tcl_ExprLong(_i_n_t_e_r_p, _s_t_r_i_n_g, _l_o_n_g_P_t_r)
  19.  
  20.      int
  21.      Tcl_ExprDouble(_i_n_t_e_r_p, _s_t_r_i_n_g, _d_o_u_b_l_e_P_t_r)
  22.  
  23.      int
  24.      Tcl_ExprBoolean(_i_n_t_e_r_p, _s_t_r_i_n_g, _b_o_o_l_e_a_n_P_t_r)
  25.  
  26.      int
  27.      Tcl_ExprString(_i_n_t_e_r_p, _s_t_r_i_n_g)
  28.  
  29. ARGUMENTS
  30.      Tcl_Interp   *_i_n_t_e_r_p       (in)      Interpreter  in   whose
  31.                                           context   to   evaluate
  32.                                           _s_t_r_i_n_g.
  33.  
  34.      char         *_s_t_r_i_n_g       (in)      Expression    to     be
  35.                                           evaluated.   Must be in
  36.                                           writable  memory   (the
  37.                                           expression parser makes
  38.                                           temporary modifications
  39.                                           to  the  string  during
  40.                                           parsing,    which    it
  41.                                           undoes  before  return-
  42.                                           ing).
  43.  
  44.      long         *_l_o_n_g_P_t_r      (out)     Pointer to location  in
  45.                                           which   to   store  the
  46.                                           integer  value  of  the
  47.                                           expression.
  48.  
  49.      int          *_d_o_u_b_l_e_P_t_r    (out)     Pointer to location  in
  50.                                           which   to   store  the
  51.                                           floating-point value of
  52.                                           the expression.
  53.  
  54.      int          *_b_o_o_l_e_a_n_P_t_r   (out)     Pointer to location  in
  55.                                           which  to store the 0/1
  56.                                           boolean  value  of  the
  57.                                           expression.
  58. _________________________________________________________________
  59.  
  60.  
  61.  
  62.  
  63. Tcl                                                             1
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. Tcl_ExprLong(3)      Tcl Library Procedures                   7.0
  71.  
  72.  
  73.  
  74. DESCRIPTION
  75.      These four procedures all evaluate an expression,  returning
  76.      the  result  in one of four different forms.  The expression
  77.      is given by the _s_t_r_i_n_g argument, and it can have any of  the
  78.      forms  accepted  by  the  expr command.  The _i_n_t_e_r_p argument
  79.      refers to an interpreter used  to  evaluate  the  expression
  80.      (e.g.  for  variables and nested Tcl commands) and to return
  81.      error information.  _I_n_t_e_r_p->_r_e_s_u_l_t is assumed to be initial-
  82.      ized  in the standard fashion when any of the procedures are
  83.      invoked.
  84.  
  85.      For all of these procedures the return value is  a  standard
  86.      Tcl  result:   TCL_OK  means  the expression was succesfully
  87.      evaluated, and TCL_ERROR means that an error occurred  while
  88.      evaluating  the  expression.   If TCL_ERROR is returned then
  89.      _i_n_t_e_r_p->_r_e_s_u_l_t will hold a message describing the error.  If
  90.      an  error  occurs  while executing a Tcl command embedded in
  91.      the expression then that error will be returned.
  92.  
  93.      If the expression is successfully evaluated, then its  value
  94.      is  returned  in  one of four forms, depending on which pro-
  95.      cedure is invoked.  Tcl_ExprLong stores an integer value  at
  96.      *_l_o_n_g_P_t_r.   If  the expression's actual value is a floating-
  97.      point number, then it is truncated to an  integer.   If  the
  98.      expression's  actual  value  is a non-numeric string then an
  99.      error is returned.
  100.  
  101.      Tcl_ExprDouble stores a floating-point value at  *_d_o_u_b_l_e_P_t_r.
  102.      If  the  expression's actual value is an integer, it is con-
  103.      verted to floating-point.  If the expression's actual  value
  104.      is a non-numeric string then an error is returned.
  105.  
  106.      Tcl_ExprBoolean stores a 0/1 integer value  at  *_b_o_o_l_e_a_n_P_t_r.
  107.      If  the expression's actual value is an integer or floating-
  108.      point number, then Tcl_ExprBoolean stores 0  at  *_b_o_o_l_e_a_n_P_t_r
  109.      if  the value was zero and 1 otherwise.  If the expression's  |
  110.      actual value is a non-numeric string then it must be one  of  |
  111.      the  values  accepted  by Tcl_GetBoolean, such as ``yes'' or  |
  112.      ``no'', or else an error occurs.
  113.  
  114.      Tcl_ExprString returns the value  of  the  expression  as  a
  115.      string stored in _i_n_t_e_r_p->_r_e_s_u_l_t.  If the expression's actual  |
  116.      value is an integer then Tcl_ExprString  converts  it  to  a  |
  117.      string  using  sprintf  with  a  ``%d''  converter.   If the  |
  118.      expression's actual value is a floating-point  number,  then  |
  119.      Tcl_ExprString  calls  Tcl_PrintDouble  to  convert  it to a  |
  120.      string.
  121.  
  122.  
  123. KEYWORDS
  124.      boolean, double, evaluate, expression, integer, string
  125.  
  126.  
  127.  
  128.  
  129. Tcl                                                             2
  130.  
  131.  
  132.  
  133.